package Rental;

use Moose;
use feature qw(switch);

has '_movie' => (
    isa => 'Movie',
    reader => 'get_movie',
    writer => '_set_movie',
    required => 1,
);

has '_days_rented' => (
    isa => 'Int',
    reader => 'get_days_rented',
    writer => '_set_days_rented',
    required => 1,
);

sub get_charge {
    my $self = shift;
    my $result = 0;
    given ($self->get_movie()->get_price_code()) {
        when(0) {
            $result = 2;
            if ($self->get_days_rented() > 2) {
                $result += ($self->get_days_rented() - 2) * 1;
            }
        }
        when(1) { $result = $self->get_days_rented() * 3 }
        when(2) {
            $result = 1;
            if ($self->get_days_rented() > 3) {
                $result += ($self->get_days_rented() - 3) * 1;
            }
        }
    }
    return $result;
}

sub get_fre_rental_points {
    my $self = shift;
    my $fre_rental_points = 1;
    if ($self->get_movie()->get_price_code() == $Movie::NEW_RELEASE && $self->get_days_rented() > 1) {
        $fre_rental_points++;
    }

    return $fre_rental_points;
}
1;
